From 4fa3210b976b98dc727566a3a175b0f9bd9a8b2b Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Wed, 7 Sep 2005 21:24:34 +0000 Subject: [PATCH] Move console tty/limit information into console directory in domain dir. Also only store port number of console event channel. Signed-off-by: Christian Limpach --- tools/console/client/main.c | 12 ++++++-- tools/console/daemon/io.c | 41 +++++++++++++++---------- tools/python/xen/xend/XendCheckpoint.py | 1 - tools/python/xen/xend/XendDomainInfo.py | 35 +++++++++++++-------- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/tools/console/client/main.c b/tools/console/client/main.c index 512e08a807..4c7b2710b8 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -170,8 +170,7 @@ int main(int argc, char **argv) { 0 }, }; - char *str_pty; - char path[1024]; + char *str_pty, *path; int spty; unsigned int len = 0; struct xs_handle *xs; @@ -214,7 +213,13 @@ int main(int argc, char **argv) signal(SIGTERM, sighandler); - snprintf(path, sizeof(path), "/console/%d/tty", domid); + path = xs_get_domain_path(xs, domid); + if (path == NULL) + err(errno, "xs_get_domain_path()"); + path = realloc(path, strlen(path) + strlen("/console/tty") + 1); + if (path == NULL) + err(ENOMEM, "realloc"); + strcat(path, "/console/tty"); str_pty = xs_read(xs, path, &len); /* FIXME consoled currently does not assume domain-0 doesn't have a @@ -252,6 +257,7 @@ int main(int argc, char **argv) err(errno, "Could not open tty `%s'", str_pty); } free(str_pty); + free(path); init_term(STDIN_FILENO, &attr); console_loop(xc_handle, domid, spty); diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 8f8f50ceee..08aeda1c46 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -144,6 +144,7 @@ static int domain_create_tty(struct domain *dom) { char *path; int master; + bool success; if ((master = getpt()) == -1 || grantpt(master) == -1 || unlockpt(master) == -1) { @@ -161,11 +162,17 @@ static int domain_create_tty(struct domain *dom) tcsetattr(master, TCSAFLUSH, &term); } - asprintf(&path, "/console/%d/tty", dom->domid); - xs_write(xs, path, slave, strlen(slave), O_CREAT); + success = asprintf(&path, "%s/tty", dom->conspath) != -1; + if (!success) + goto out; + success = xs_write(xs, path, slave, strlen(slave), O_CREAT); free(path); + if (!success) + goto out; - asprintf(&path, "/console/%d/limit", dom->domid); + success = asprintf(&path, "%s/limit", dom->conspath) != -1; + if (!success) + goto out; data = xs_read(xs, path, &len); if (data) { dom->buffer.max_capacity = strtoul(data, 0, 0); @@ -175,6 +182,9 @@ static int domain_create_tty(struct domain *dom) } return master; + out: + close(master); + return -1; } /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */ @@ -218,7 +228,7 @@ static int domain_create_ring(struct domain *dom) err = xs_gather(xs, dom->conspath, "ring-ref", "%u", &ring_ref, - "console_channel/port1", "%i", &local_port, + "port", "%i", &local_port, NULL); if (err) goto out; @@ -289,6 +299,17 @@ static struct domain *create_domain(int domid) } dom->domid = domid; + + dom->conspath = xs_get_domain_path(xs, dom->domid); + if (dom->conspath == NULL) + goto out; + s = realloc(dom->conspath, strlen(dom->conspath) + + strlen("/console") + 1); + if (s == NULL) + goto out; + dom->conspath = s; + strcat(dom->conspath, "/console"); + dom->tty_fd = domain_create_tty(dom); dom->is_dead = false; dom->buffer.data = 0; @@ -302,18 +323,6 @@ static struct domain *create_domain(int domid) dom->page = NULL; dom->evtchn_fd = -1; - dom->conspath = NULL; - - dom->conspath = xs_get_domain_path(xs, dom->domid); - if (dom->conspath == NULL) - goto out; - s = realloc(dom->conspath, strlen(dom->conspath) + - strlen("/console") + 1); - if (s == NULL) - goto out; - dom->conspath = s; - strcat(dom->conspath, "/console"); - if (!watch_domain(dom, true)) goto out; diff --git a/tools/python/xen/xend/XendCheckpoint.py b/tools/python/xen/xend/XendCheckpoint.py index 7a0f43fc7d..345f83979d 100644 --- a/tools/python/xen/xend/XendCheckpoint.py +++ b/tools/python/xen/xend/XendCheckpoint.py @@ -173,7 +173,6 @@ def restore(xd, fd): if m: dominfo.console_mfn = int(m.group(2)) dominfo.exportToDB(save=True, sync=True) - dominfo.publish_console() try: l = child.fromchild.readline() except: diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index e954fad70f..1100d28b85 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -298,15 +298,14 @@ class XendDomainInfo: self.store_channel.saveToDB(self.db.addChild("store_channel"), save=save) if self.console_channel: - self.console_channel.saveToDB(self.db.addChild("console/console_channel"), - save=save) + self.db['console/port'] = "%i" % self.console_channel.port1 if self.image: self.image.exportToDB(save=save, sync=sync) self.db.exportToDB(self, fields=self.__exports__, save=save, sync=sync) def importFromDB(self): self.db.importFromDB(self, fields=self.__exports__) - self.store_channel = self.eventChannel("store_channel") + self.store_channel = self.eventChannelOld("store_channel") def setdom(self, dom): """Set the domain id. @@ -654,7 +653,6 @@ class XendDomainInfo: self.configure_restart() self.construct_image() self.configure() - self.publish_console() self.exportToDB(save=True) except Exception, ex: # Catch errors, cleanup and re-raise. @@ -845,7 +843,7 @@ class XendDomainInfo: id, self.name, self.memory) self.setdom(id) - def eventChannel(self, key): + def eventChannelOld(self, key): """Create an event channel to the domain. If saved info is available recreate the channel. @@ -854,11 +852,27 @@ class XendDomainInfo: db = self.db.addChild(key) return EventChannel.restoreFromDB(db, 0, self.id) + def eventChannel(self, path=None, key=None): + """Create an event channel to the domain. + + @param path under which port is stored in db + """ + port = 0 + try: + if path and key: + if path: + db = self.db.addChild(path) + else: + db = self.db + port = int(db[key].getData()) + except: pass + return EventChannel.interdomain(0, self.id, port1=port, port2=0) + def create_channel(self): """Create the channels to the domain. """ - self.store_channel = self.eventChannel("store_channel") - self.console_channel = self.eventChannel("console/console_channel") + self.store_channel = self.eventChannelOld("store_channel") + self.console_channel = self.eventChannel("console", "port") def create_configured_devices(self): devices = sxp.children(self.config, 'device') @@ -1071,11 +1085,6 @@ class XendDomainInfo: backend = blkif.getBackend(0) backend.connect(recreate=self.recreate) - def publish_console(self): - db = DBMap(db=XenNode("/console/%d" % self.id)) - db['domain'] = self.db.getPath() - db.saveDB(save=True) - def configure_fields(self): """Process the vm configuration fields using the registered handlers. """ @@ -1143,7 +1152,7 @@ class XendDomainInfo: def dom0_init_store(self): if not self.store_channel: - self.store_channel = self.eventChannel("store_channel") + self.store_channel = self.eventChannelOld("store_channel") self.store_mfn = xc.init_store(self.store_channel.port2) if self.store_mfn >= 0: self.db.introduceDomain(self.id, self.store_mfn, -- 2.30.2